package com.douqu.game.core.entity.sprite;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.GameObject;

/**
 * Created by bean on 2017/7/14.
 */
public class Sprite extends GameObject {

    /** 模型 */
    public String model;

    /** 头像 */
    public String avatar;

    /**
     * 等级
     */
    public int lv;

    /**
     * 当前总经验
     */
    public int exp;

    public int uid;


    public Sprite()
    {
        this.lv = 1;
    }

    @Override
    public void copyTo(GameObject gameObject)
    {
        super.copyTo(gameObject);

        Sprite sprite = (Sprite) gameObject;
        sprite.model = this.model;
        sprite.avatar = this.avatar;
        sprite.lv = this.lv;
        sprite.exp = this.exp;
    }

    @Override
    public void writeTo(ByteBuffer buffer)
    {
        super.writeTo(buffer);

        buffer.writeShort(lv);
        buffer.writeInt(exp);
    }

    @Override
    public void loadFrom(ByteBuffer buffer)
    {
        super.loadFrom(buffer);

        lv = buffer.readShort();
        exp = buffer.readInt();
    }


    /**
     * 获取属性增加
     * @param attrId
     * @return
     */
    public int getAttribute(int attrId)
    {
        return 0;
    }

    /**
     * 获取对应的属性加成比例
     * @return 如果是加成50%则是返回50
     */
    public int getAttributePlus(int attrId)
    {
        return 0;
    }

    /**
     * 加经验
     * @param value
     */
    public void addExp(int value)
    {
        int beforeExp = this.exp;

        this.exp += value;
        exp = exp < 0 ? 0 : exp;

        if(exp != beforeExp)
            updateLv();
    }

    public void updateLv()
    {
        //子类里写
    }


    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public int getLv() {
        return lv;
    }

    public void setLv(int lv) {
        this.lv = lv;
    }

    public int getExp() {
        return exp;
    }

    public void setExp(int exp) {
        this.exp = exp;
    }

    public int getUid() {
        return uid;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }
}
